using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using C4F.DevKit.Messaging;

namespace MapiApplication
{
    public partial class SendMailOptions : Form
    {
        private Mail mail;
        private MapiManager manager;
        public SendMailOptions()
        {
            InitializeComponent();
        }

        public SendMailOptions(ref Mail mail, ref MapiManager manager)
        {
            InitializeComponent();

            this.mail = mail;
            this.manager = manager;
            if (this.mail != null)
            {
                txtFrom.Text = mail.From ;
                chkBodyHtml.Checked = mail.IsBodyHtml;

                txtReplyTo.Text = mail.ReplyTo;
                txtSender.Text = mail.Sender;
                cmbSubjectEndoding.Text = mail.SubjectEncoding.ToString();
                cmbMailPriority.Text = mail.Priority.ToString();
                cmbBodyEncoding.Text = mail.BodyEncoding.ToString();
                cmbAlternateView.Text = mail.AlternateViews.ToString();
                cmbDeliveryNotification.Text = mail.DeliveryNotificationOptions.ToString();
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            //this.manager.CreateCredentialsToSendMail(txtUsername.Text, txtPassword.Text,);
            mail.From = txtFrom.Text;
            mail.IsBodyHtml = chkBodyHtml.Checked;
            
            mail.ReplyTo = txtReplyTo.Text;
            mail.Sender = txtSender.Text;


            switch (cmbSubjectEndoding.Text)
            {
                case "ASCII":
                    mail.SubjectEncoding = C4F.DevKit.Messaging.Encoding.ASCII;
                    break;
                case "BigEndianUnicode":
                    mail.SubjectEncoding = C4F.DevKit.Messaging.Encoding.BigEndianUnicode;
                    break;
                case "Default":
                    mail.SubjectEncoding = C4F.DevKit.Messaging.Encoding.Default;
                    break;
                case "Unicode":
                    mail.SubjectEncoding = C4F.DevKit.Messaging.Encoding.Unicode;
                    break;
                case "UTF32":
                    mail.SubjectEncoding = C4F.DevKit.Messaging.Encoding.UTF32;
                    break;
                case "UTF7":
                    mail.SubjectEncoding = C4F.DevKit.Messaging.Encoding.UTF7;
                    break;
                case "UTF8":
                    mail.SubjectEncoding = C4F.DevKit.Messaging.Encoding.UTF8;
                    break;
            }

            switch (cmbMailPriority.Text)
            {
                case "High":
                    mail.Priority = Priorities.High;
                    break;
                case "Low":
                    mail.Priority = Priorities.Low;
                    break;
                case "Normal":
                    mail.Priority = Priorities.Normal;
                    break;
            }

            switch (cmbDeliveryNotification.Text)
            {
                case "None":
                    mail.DeliveryNotificationOptions = DeliveryNotificationOptions.None;
                    break;
                case "Never":
                    mail.DeliveryNotificationOptions = DeliveryNotificationOptions.Never;
                    break;
                case "OnFailure":
                    mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                    break;
                case "OnSuccess":
                    mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
                    break;
                case "Delay":
                    mail.DeliveryNotificationOptions = DeliveryNotificationOptions.Delay;
                    break;
            }

            switch (cmbBodyEncoding.Text)
            {
                case "ASCII":
                    mail.BodyEncoding = C4F.DevKit.Messaging.Encoding.ASCII;
                    break;
                case "BigEndianUnicode":
                    mail.BodyEncoding = C4F.DevKit.Messaging.Encoding.BigEndianUnicode;
                    break;
                case "Default":
                    mail.BodyEncoding = C4F.DevKit.Messaging.Encoding.Default;
                    break;
                case "Unicode":
                    mail.BodyEncoding = C4F.DevKit.Messaging.Encoding.Unicode;
                    break;
                case "UTF32":
                    mail.BodyEncoding = C4F.DevKit.Messaging.Encoding.UTF32;
                    break;
                case "UTF7":
                    mail.BodyEncoding = C4F.DevKit.Messaging.Encoding.UTF7;
                    break;
                case "UTF8":
                    mail.BodyEncoding = C4F.DevKit.Messaging.Encoding.UTF8;
                    break;
            }


            switch (cmbAlternateView.Text)
            {
                case "Html":
                    mail.AlternateViews = AlternateBodyViews.Html;
                    break;
                case "Plain":
                    mail.AlternateViews = AlternateBodyViews.Plain;
                    break;
                case "RichText":
                    mail.AlternateViews = AlternateBodyViews.RichText;
                    break;
                case "Xml":
                    mail.AlternateViews = AlternateBodyViews.Xml;
                    break;
            }

            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }             
    }
}